#include "db_con.h"
#include "sol/sol.hpp"


bool CfgMgr::Init()
{
	L_DEBUG("init cfg");
	{
		sol::state lua;
		lua.open_libraries(sol::lib::base,
			sol::lib::package,
			sol::lib::table,
			sol::lib::string);

		sol::protected_function_result r = lua.do_file("dbproxy.lua");
		if (!r.valid())
		{
			sol::error err = r;
			std::string what = err.what();
			LERROR("zone.lua load fail error:", what);
			return false;
		}
		m_cfg.ip      = lua["dbproxyIp"];
		m_cfg.port    = lua["dbproxyPort"];
		auto& db      = m_cfg.mysql_db;
		auto&& lua_db = lua["mysql_db"];
		db.db_ip      = lua_db["db_ip"];
		db.db_port    = lua_db["db_port"];
		db.db_user    = lua_db["db_user"];
		db.db_psw     = lua_db["db_psw"];
		db.db_name    = lua_db["db_name"];
	}
	return true;
}
